package com.borya.dao.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.borya.dao.ServerConfDAO;
import com.borya.framework.annotation.Component;
import com.borya.util.Constant;

@Component("serverConfDAOImpl")
public class ServerConfDAOImpl extends BaseDAOImpl implements ServerConfDAO {

//	private Logger log = Logger.getLogger(getClass());
    private String COMMON_KEY = "common";
    private String SELF_KEY = "ums";
    @Override
    public List<String> allowIps() {
        final String key = Constant.IPS;
        final String commonIps = redis_hget(key,COMMON_KEY);
        List<String> allowIps = new ArrayList<>();
        if(commonIps != null){
            allowIps.addAll(Stream.of(commonIps.split(",")).collect(Collectors.toList()));
        }
        final String selfIps = redis_hget(key,SELF_KEY);
        if(selfIps != null){
            allowIps.addAll(Stream.of(selfIps.split(",")).collect(Collectors.toList()));
        }
        return allowIps;
    }

}
